package com.guigu.www.erp.dehao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.www.erp.common.pojo.PageVo;
import com.guigu.www.erp.dehao.dao.UserMapper;
import com.guigu.www.erp.dehao.dao.UserRoleMapper;
import com.guigu.www.erp.dehao.pojo.User;
import com.guigu.www.erp.dehao.pojo.UserRole;
import com.guigu.www.erp.dehao.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserRoleMapper mapper;

    @Override
    public void deleteByPrimaryKey(Integer userId) {
        userMapper.deleteByPrimaryKey(userId);
    }

    @Override
    public void insertSelective(User user) {
        userMapper.insertSelective(user);
    }

    @Override
    public User selectByPrimaryKey(Integer userId) {
        return userMapper.selectByPrimaryKey(userId);
    }

    @Override
    public void updateByPrimaryKeySelective(User user) {
        userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public User login(User user) {
        return userMapper.login(user);
    }

    @Override
    public User accountIsExist(String userAccount) {
        return userMapper.accountIsExist(userAccount);
    }

    @Override
    public PageVo<User> findAllUser1(Integer pageNum,Integer pageSize,String userName) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> allUser1 = userMapper.findAllUser1("%"+userName+"%");
        PageInfo<User> info  = new PageInfo<>(allUser1);
        return new PageVo<>(info.getTotal(),info.getList());
    }

    @Override
    public PageVo<User> findAllUser0(Integer pageNum,Integer pageSize,String userName) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> allUser0 = userMapper.findAllUser0("%"+userName+"%");
        PageInfo<User> info  = new PageInfo<>(allUser0);
        return new PageVo<>(info.getTotal(),info.getList());
    }

    @Override
    public void insert(UserRole record) {
        mapper.insertSelective(record);
    }

    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }
}
